<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<script type="text/javascript">
	$(document).ready(function(){
		$("#listBtn").click(function(){
			if(confirm("문의글 목록으로 돌아 가시겠습니까?")){
				location.href="getQuestionBoardList.do?pageNo=${requestScope.pageNo}";
			}else{
				return;
			}
		});
		$("#deleteBtn").click(function(){
			$("#check").html("");
			$("#check").html("<input type='password' name='password' id='password'><input type='button' id='checkPassword' value='비밀번호 확인'>");
			$("#checkPassword").click(function(){
				if($("#password").val()=="${sessionScope.cvo.password }"){
					var restep=${requestScope.qvo.restep };
					var ref=${requestScope.qvo.ref };
					if(restep!="0"){
						if(confirm("글을 삭제 하시겠습니까?")){
							location.href="deleteQuestionBoard.do?no=${requestScope.qvo.no }&pageNo=${requestScope.pageNo}";
						}else{
							return;
						}
					}else{
						$.ajax({
							type:"post",
							url:"replyCheck.do",
							data:"ref="+ref,
							success:function(result){
								if(result=="1"){
									if(confirm("글을 삭제 하시겠습니까?")){
										location.href="deleteQuestionBoard.do?no=${requestScope.qvo.no }&pageNo=${requestScope.pageNo}";
									}else{
										return;
									}
								}else{
									alert("답글이 있을경우 본문을 삭제할 수 없습니다!");
									return;
								}
							}
						});
					}
				}else{
					alert("비밀번호가 다릅니다!");
					return;
				}
			});
		});
		$("#updateBtn").click(function(){
			$("#check").html("");
			$("#check").html("<input type='password' name='password' id='password'><input type='button' id='checkPassword' value='비밀번호 확인'>");
			$("#checkPassword").click(function(){
				if($("#password").val()=="${sessionScope.cvo.password }"){
					if(confirm("글을 수정 하시겠습니까?")){
						location.href="updateQuestionBoardView.do?no=${requestScope.qvo.no }&pageNo=${requestScope.pageNo}";
					}else{
						return;
					}
				}else{
					alert("비밀번호가 다릅니다!");
					return;
				}
			});
		});
		$("#replyBtn").click(function(){
			if(confirm("해당 글에 답글을 작성 하시겠습니까?")){
				location.href="replyQuestionBoardView.do?no=${requestScope.qvo.no }&pageNo=${requestScope.pageNo}";
			}else{
				return;
			}
		});
	});
</script>

	<table width="450">
		<thead align="left">
		<tr>
			<td width="15%">작성자</td>
			<td width="60%">${requestScope.qvo.id }</td>
			<td width="15%">조회수</td>
			<td >${requestScope.qvo.count }</td>
		</tr>
		<tr>
			<td width="15%">날짜</td>
			<td width="60%">${requestScope.qvo.questionDate}</td>
			<td width="15%">글번호</td>
			<td >${requestScope.qvo.no }</td>
		</tr>
		<tr>
			<td width="15%">제목</td>
			<td colspan="3" width="85%">${requestScope.qvo.title}</td>
		</thead>
		<tbody align="left">
		<tr>
			<td colspan="4" align="center">
				<textarea cols="52" rows="10" name="content" readonly>${requestScope.qvo.content }</textarea></td>
		</tr>
		</tbody>
		<tfoot align="left">
		<tr>
			<td colspan="4">
				<input type="button" id="listBtn" value="목록 보기">
				<c:choose>
					<c:when test="${sessionScope.svo!=null}">
						<input type="button" id="replyBtn" value="답글 쓰기">
					</c:when>
					<c:when test="${requestScope.qvo.replyId==sessionScope.cvo.id}">
						<input type="button" id="replyBtn" value="답글 쓰기">
					</c:when>
				</c:choose>
				<c:choose>
					<c:when test="${sessionScope.cvo.id==requestScope.qvo.id}">
						<input type="button" id="updateBtn" value="수정 하기">
						<input type="button" id="deleteBtn" value="삭제 하기">
					</c:when>
				</c:choose>
			</td>
		</tr>
		<tr>
			<td colspan="4"><span id="check"></span></td>
		</tr>
		</tfoot>
	</table>
